Bugfix: Remove close-handler for powershell child process #865
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR tries to fix a race condition which occurs when calling powerShellRelease and powerShellStart in sequence.
Background: We need to restart the powershell instance from time to time in a long running process as its memory consumption grows without limit.
Currently, 2 problems can arise in the close-event handler if powerShellStart() is called after powerShellRelease():
The variable '_psChild' could be null if the close-event was fired after the null assignment but before the spawn() call returns.
(in my tests when powerShellStart is called 1s after powerShellRelease).
The signal from the kill()-call could be delivered to the newly created powershell subprocess.
(in my tests when powerShellStart is called directly after powerShellRelease).
My fix removes the problematic lines, because I don't see a reason for calling 'kill' on the subprocess in its 'close'-event handler.
According to the NodeJS documentation, this handler is called 'after a process has ended and the stdio streams of a child process have been closed'1. Maybe I'm missing something here, in that case we could solve the referencing issue using a local variable for the result of 'spawn', use that in the handler and assign the local variable to the global one after setting the handlers.